package com.intct.hbase.ddl.table;

import com.intct.hbase.ddl.namespace.AbsNamespace;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;

import java.io.IOException;

/**
 * @author gufg
 * @since 2025-07-10 16:25
 */
public class Drop extends AbsNamespace {

    /*
命名空间名称
*/
    private String namespace;

    /*
    声明表名
     */
    private String tableName;

    public Drop(String namespace, String tableName) {
        this.namespace = namespace;
        this.tableName = tableName;
    }


    @Override
    public void execCommand(Admin admin) throws IOException {

        TableName hbaseTableName = TableName.valueOf(namespace, tableName);

        // 判断表是否存，如果存在则禁用表、删除表
        if (admin.tableExists(hbaseTableName)) {
            if (!admin.isTableDisabled(hbaseTableName)) {
                // 禁用表
                admin.disableTable(hbaseTableName);
            }

            // 删除表
            admin.deleteTable(hbaseTableName);
        }
    }

    public static void main(String[] args) throws IOException {
        new Drop("intct82", "t02").start();
    }
}
